import cv2 #opencv读取的格式是BGR
import numpy as np
import matplotlib.pyplot as plt
from numpy.lib.function_base import gradient#Matplotlib是RGB

img = cv2.imread('dige.png')


sobelx = cv2.Sobel(img, cv2.CV_64F, 1, 0, ksize=3)
sobelx = cv2.convertScaleAbs(sobelx)



sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=3)
sobely = cv2.convertScaleAbs(sobely)  


sobelxy = cv2.addWeighted(sobelx,0.5,sobely,0.5,0)


cv2.imshow('sobelx y', np.hstack((img,sobelx, sobely, sobelxy)))
cv2.waitKey(0)
cv2.destroyAllWindows()